# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=mariadb-connector-c
pkgver=3.3.9
pkgrel=0
pkgdesc="The MariaDB Native Client library (C driver)"
url="https://mariadb.org/"
arch="all"
license="LGPL-2.1-or-later"
depends_dev="openssl-dev>3 zlib-dev"
makedepends="$depends_dev cmake samurai"
options="!check" # no testsuite
replaces="mariadb-client-libs"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/mariadb-corporation/mariadb-connector-c/archive/refs/tags/v$pkgver.tar.gz
	incorrect-sys-poll.patch
	unused-parameter.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	# INSTALL_LIBDIR and INSTALL_INCLUDEDIR are relative to CMAKE_INSTALL_PREFIX.
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DINSTALL_LIBDIR=lib \
		-DINSTALL_INCLUDEDIR=include/mysql \
		\
		-DMARIADB_PORT=3306 \
		-DMARIADB_UNIX_ADDR=/run/mysqld/mysqld.sock \
		-DWITH_EXTERNAL_ZLIB=YES \
		-DWITH_MYSQLCOMPAT=ON \
		-DWITH_SSL=OPENSSL \
		$CMAKE_CROSSOPTS
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# purge static libs
	rm "$pkgdir"/usr/lib/*.a

	# Docs conflict with mariadb-doc
	rm -r "$pkgdir"/usr/man

	# compat symlinks
	ln -s mariadb_config "$pkgdir"/usr/bin/mysql_config
	ln -s mariadb_version.h "$pkgdir"/usr/include/mysql/mysql_version.h
}

dev() {
	default_dev
	replaces="mariadb-dev"
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
}

sha512sums="
2365628248d83fdb31ad8aedc2209aaa855262d799183dbc6445d3419f3b769d782232d590add33e7aa2b9d226417a9cdf65707bb95768a60b5215d839d6c55b  mariadb-connector-c-3.3.9.tar.gz
ca55213d91a1495cc85a972528820af058ea194073f050389fbac829e077fc179fa7c0422b18953ebe7751379af7e670a5fffef9bd642cd2051d35e0410ab4f3  incorrect-sys-poll.patch
1e71e01ffb2a95833ae08fe6bb72c75f762b57ea5919d27be518e40c4cb1dee16ac2609fe4a663a1ca7781523046285ab1c757b5c82bce42ef4b5ecd75d5ed90  unused-parameter.patch
"
